# - Find Open Robotics Automation Virtual Enviornment (OpenRAVE) Installation
# http://www.openrave.org
#
# OpenRAVE provides an environment for testing, developing, and deploying motion planning algorithms
# in real-world robotics applications. The main focus is on simulation and analysis of kinematic and
# geometric information related to motion planning. OpenRAVE’s stand-alone nature allows is to be easily
# integrated into existing robotics systems. An important target application is industrial robotics automation.
#
# Users can set the following variables before calling the module:
#  OpenRAVE_DIR - The preferred installation prefix for searching for OpenRAVE. Set by the user.
#
# OpenRAVE_ROOT_DIR - the root directory where the installation can be found
# OpenRAVE_CXX_FLAGS - extra flags for compilation
# OpenRAVE_LINK_FLAGS - extra flags for linking
# OpenRAVE_INCLUDE_DIRS - include directories
# OpenRAVE_LIBRARY_DIRS - link directories
# OpenRAVE_LIBRARIES - libraries to link plugins with
# OpenRAVE_CORE_LIBRARIES - libraries to link openrave run-time with
# OpenRAVE_PYTHON_DIR - the version-specific path where openravepy.__init__ is, necessary for using shared resources like linking with openravepy_int.so or using ikfast.h
# OpenRAVE_Boost_VERSION - the boost version openrave was compiled with

#==================================================================================
# Copyright (C) 2009-2011 Rosen Diankov
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
#  License text for the above reference.)
#==================================================================================
@PACKAGE_INIT@

cmake_policy(SET CMP0007 NEW)

# Get prefix, go up 2 levels
get_filename_component(_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_PREFIX "${_PREFIX}" PATH)
get_filename_component(_PREFIX "${_PREFIX}" PATH)
get_filename_component(OpenRAVE_ROOT_DIR "${_PREFIX}" PATH)

set_and_check(OpenRAVE_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@OPENRAVE_INCLUDE_INSTALL_DIR@")
set_and_check(OpenRAVE_RAPIDJSON_INCLUDE_DIR "@RAPIDJSON_INCLUDES@")

set( OpenRAVE_INCLUDE_DIRS ${OpenRAVE_INCLUDE_DIR} ${OpenRAVE_RAPIDJSON_INCLUDE_DIR} )
set( OpenRAVE_Boost_VERSION "@Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@" )
set( OpenRAVE_BLA_VENDOR "@BLA_VENDOR@" )
set( OpenRAVE_CXX_FLAGS "-DOPENRAVE_DLL -DOPENRAVE_CORE_DLL" )

find_package(Boost ${OpenRAVE_Boost_VERSION} REQUIRED COMPONENTS filesystem system thread)
find_package(LibXml2 REQUIRED)

include(${CMAKE_CURRENT_LIST_DIR}/openrave-targets.cmake)

set( OpenRAVE_PYTHON2 @OPT_PYTHON@ )
set( OpenRAVE_PYTHON3 @OPT_PYTHON3@ )

if (OpenRAVE_PYTHON2)
  find_package(Python 2.7 REQUIRED COMPONENTS Interpreter Development NumPy)

  set( OpenRAVE_PYTHON2_INCLUDE_DIRS "${Python_INCLUDE_DIRS};${Python_NumPy_INCLUDE_DIRS}" )
  set( OpenRAVE_PYTHON2_DIR "${OpenRAVE_ROOT_DIR}/@OPENRAVEPY2_VER_INSTALL_DIR@")
  set( OpenRAVE_USE_PYBIND11_PYTHON_BINDINGS @USE_PYBIND11_PYTHON_BINDINGS@)

  # Backwards compat: Refer to python 2
  set( OpenRAVE_PYTHON_INCLUDE_DIRS ${OpenRAVE_PYTHON2_INCLUDE_DIRS} CACHE STRING "This is for backward compatibility with deprecated CMake declarations." FORCE)
  set( OpenRAVE_PYTHON_DIR "${OpenRAVE_PYTHON2_DIR}")

  if (OpenRAVE_USE_PYBIND11_PYTHON_BINDINGS)
    set(PYBIND11_FINDPYTHON ON)
    find_package(pybind11 REQUIRED CONFIG)
  else()
    find_package(Boost ${OpenRAVE_Boost_VERSION} REQUIRED COMPONENTS python)
  endif()
endif()

if (OpenRAVE_PYTHON3)
  find_package(Python3 3.9 REQUIRED COMPONENTS Interpreter Development NumPy)

  set( OpenRAVE_PYTHON3_INCLUDE_DIRS "${Python3_INCLUDE_DIRS};${Python3_NumPy_INCLUDE_DIRS}" )
  set( OpenRAVE_PYTHON3_DIR "${OpenRAVE_ROOT_DIR}/@OPENRAVEPY3_VER_INSTALL_DIR@")
  set( OpenRAVE_USE_PYBIND11_PYTHON3_BINDINGS @USE_PYBIND11_PYTHON3_BINDINGS@)

  # Set these values if Python2 is not present.
  if (NOT OpenRAVE_PYTHON2)
    set( OpenRAVE_PYTHON_INCLUDE_DIRS ${OpenRAVE_PYTHON3_INCLUDE_DIRS} CACHE STRING "This is for backward compatibility with deprecated CMake declarations." FORCE)
    set( OpenRAVE_PYTHON_DIR "${OpenRAVE_PYTHON3_DIR}")
  endif()

  if (OpenRAVE_USE_PYBIND11_PYTHON3_BINDINGS)
    set(PYBIND11_FINDPYTHON ON)
    find_package(pybind11 REQUIRED CONFIG)
  else()
    find_package(Boost ${OpenRAVE_Boost_VERSION} REQUIRED COMPONENTS python)
  endif()
endif()

# Backward compatibility only.
get_target_property(libopenrave_LOCATION OpenRAVE::libopenrave LOCATION)
get_target_property(libopenrave-core_LOCATION OpenRAVE::libopenrave-core LOCATION)
set(OpenRAVE_LIBRARIES OpenRAVE::libopenrave)
set(OpenRAVE_CORE_LIBRARIES OpenRAVE::libopenrave;OpenRAVE::libopenrave-core)

find_package(Eigen3 3.3.7 REQUIRED)

message(STATUS "Found OpenRAVE ${OpenRAVE_VERSION}, compiled with Boost ${OpenRAVE_Boost_VERSION}.")

mark_as_advanced(
    libopenrave_LOCATION
    libopenrave-core_LOCATION
)
